package leetcode;

import java.util.Arrays;

import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/12/21 8:40
 */
public class Test242 {


    /**
     * 242. 有效的字母异位词
     */

    @Test
    public void test() {
        String s = "anagram", t = "nagaram";
        System.out.println(isAnagram(s, t));
    }


    public boolean isAnagram(String s, String t) {
        char[] chars = s.toCharArray();
        char[] chars1 = t.toCharArray();
        Arrays.sort(chars);
        Arrays.sort(chars1);
        if (s.length() != t.length()) return false;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] != chars1[i]) {
                return false;
            }
        }
        return true;
    }

}
